//
//  HJPostInformationSelectImageCell.m
//  KaiChat
//
//  Created by lx on 2024/3/14.
//

#import "HJPostInformationSelectImageCell.h"

@interface HJPostInformationSelectImageCell()

@property (nonatomic, weak) UIImageView *imageView;
@property (nonatomic, weak) UIButton *deleteButton;
@property (nonatomic, weak) UIImageView *videoFlagView;

@end

@implementation HJPostInformationSelectImageCell

- (void)settingSubView {
    [super settingSubView];

    UIImageView *imageView = [UIImageView addToView:self.contentView];
    imageView.addCornerRadius(10);
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.offset(0);
        make.width.height.offset(HZoom(106));
    }];
    
    UIButton *deleteButton = [UIButton addToView:self.contentView];
    [deleteButton setBackgroundImage:[UIImage imageNamed:@"delete_icon"] forState:UIControlStateNormal];
    [deleteButton addTarget:self action:@selector(didClickDeleteButton) forControlEvents:UIControlEventTouchUpInside];
    [deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(imageView.mas_right);
        make.centerY.equalTo(imageView.mas_top);
        make.width.height.offset(HZoom(20));
    }];
    
    UIImageView *videoFlagView = [UIImageView addToView:imageView];
    videoFlagView.image = [UIImage imageNamed:@"video_flag"];
    [videoFlagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
    }];
    
    videoFlagView.hidden = YES;
    
    _videoFlagView = videoFlagView;
    _deleteButton = deleteButton;
    _imageView = imageView;
}

- (void)didClickDeleteButton {
    if (_didClickDeleteButtonBlock) {
        _didClickDeleteButtonBlock(self.model);
    }
}

- (void)setModel:(HJSelectImageModel *)model {
    _model = model;
    
    _imageView.image = model.image;
    if (model.isAdd) {
        _deleteButton.hidden = YES;
    } else {
        _deleteButton.hidden = NO;
    }
    _videoFlagView.hidden = !model.asset;
}

@end
